package com.atguigu.daijia.order.controller;

import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.model.entity.order.OrderInfo;
import com.atguigu.daijia.model.form.order.OrderInfoForm;
import com.atguigu.daijia.model.form.order.StartDriveForm;
import com.atguigu.daijia.model.form.order.UpdateOrderBillForm;
import com.atguigu.daijia.model.form.order.UpdateOrderCartForm;
import com.atguigu.daijia.model.vo.order.CurrentOrderInfoVo;
import com.atguigu.daijia.order.service.OrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Tag(name = "订单API接口管理")
@RestController
@RequestMapping(value="/order/info")
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderInfoController {
	
    @Autowired
    private OrderInfoService orderInfoService;

    @Operation(summary = "保存订单")
    @PostMapping("/submitOrder")
    public Result<Long> submitOrder(@RequestBody OrderInfoForm orderInfoForm) {
    	return Result.ok(orderInfoService.submitOrder(orderInfoForm));
    }

    @Operation(summary = "根据订单查询订单状态")
    @GetMapping("/getOrderStatus/{orderId}")
    public Result<Integer> getOrderStatus(@PathVariable Long orderId) {
        return Result.ok(orderInfoService.getOrderStatus(orderId));
    }

    @Operation(summary = "司机枪单")
    @GetMapping("/robNewOrder/{driverId}/{orderId}")
    Result<Boolean> robNewOrder(@PathVariable("driverId") Long driverId,@PathVariable("orderId") Long orderId){
        return Result.ok(orderInfoService.robNewOrder(driverId,orderId));
    }

    @Operation(summary = "查询客户当前订单")
    @GetMapping("/searchCustomerCurrentOrder/{userId}")
    Result<CurrentOrderInfoVo> searchCustomerCurrentOrder(@PathVariable("userId") Long userId){
        return Result.ok(orderInfoService.searchCustomerCurrentOrder(userId));
    }

    @Operation(summary = "查询客户当前订单")
    @GetMapping("/searchDriverCurrentOrder/{driverId}")
    Result<CurrentOrderInfoVo> searchDriverCurrentOrder(@PathVariable("driverId") Long driverId){
        return Result.ok(orderInfoService.searchDriverCurrentOrder(driverId));
    }


    @Operation(summary = "根据订单id查询订单详情")
    @GetMapping("/getOrderInfo/{orderId}")
    Result<OrderInfo> getOrderInfo(@PathVariable("orderId") Long orderId){
        return Result.ok(orderInfoService.getById(orderId));
    }

    @Operation(summary = "司机到达代驾起点")
    @GetMapping("/driverArriveStartLocation/{orderId}/{driverId}")
    Result<Boolean> driverArriveStartLocation(@PathVariable("orderId") Long orderId,@PathVariable("driverId") Long driverId){
        return Result.ok(orderInfoService.driverArriveStartLocation(orderId,driverId));
    }

    @Operation(summary = "司机更新代驾车辆信息")
    @PostMapping("/updateOrderCart")
    Result<Boolean> updateOrderCart(@RequestBody UpdateOrderCartForm updateOrderCartForm){
        return Result.ok(orderInfoService.updateOrderCart(updateOrderCartForm));
    }

    @Operation(summary = "开始代驾")
    @PostMapping("/startDrive")
    Result<Boolean> startDrive(@RequestBody StartDriveForm startDriveForm){
        return Result.ok(orderInfoService.startDrive(startDriveForm));
    }

    @Operation(summary = "根据时间段获取订单数")
    @GetMapping("/getOrderNumByTime/{startTime}/{endTime}")
    public Result<Long> getOrderNumByTime(@PathVariable String startTime, @PathVariable String endTime) {
        return Result.ok(orderInfoService.getOrderNumByTime(startTime, endTime));
    }

    @Operation(summary = "结束代驾服务更新订单账单")
    @PostMapping("/endDrive")
    public Result<Boolean> endDrive(@RequestBody UpdateOrderBillForm updateOrderBillForm) {
        return Result.ok(orderInfoService.endDrive(updateOrderBillForm));
    }



























}

